package com.simple.gateway.center.domian.message;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

/**
 * 项目: simple-gateway-core
 *
 * 功能描述: 消息推送
 *
 * @author: WuChengXing
 *
 * @create: 2023-08-10 10:55
 **/
@Component
@Slf4j
public class Publisher {

    private final RedisTemplate<String, Object> redisMessageTemplate;

    @Autowired
    public Publisher(RedisTemplate<String, Object> redisMessageTemplate) {
        this.redisMessageTemplate = redisMessageTemplate;
    }

    public void pushMessage(String topic, Object message) {
        try {
            redisMessageTemplate.convertAndSend(topic, message);
        } catch (Exception e) {
            log.error("发送消息失败：【{}】", topic, e);
        }

    }
}
